<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html lang="zh-cn">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>  
    <link rel="stylesheet" href="<%=path %>/admin/css/pintuer.css">
    <link rel="stylesheet" href="<%=path %>/admin/css/admin.css">
    <link rel="stylesheet" href="<%=path %>/admin/css/style.css">
    <link rel="stylesheet" href="<%=path %>/admin/font-awesome-4.7.0/css/font-awesome.css">
    <script src="<%=path %>/admin/js/jquery.js"></script>
    <script src="<%=path %>/admin/js/pintuer.js"></script>  
    <link rel="stylesheet" href="<%=path %>/static/css/paging.css" />
    <link rel="stylesheet" href="<%=path %>/admin/jedate/skin/jedate.css">
    <script src="<%=path %>/static/js/paging.js"></script>
    <script src="<%=path %>/static/js/city-data.js"></script>
    <script src="<%=path %>/admin/jedate/jquery.jedate.js"></script> 
</head>
<body>
<form method="post" action="<%=path %>/bUserInfo/memberList" id="listform">
    <input type="hidden" id="state" name="state">
	<input type="hidden" id="totalSize" name="totalSize" value="${totalSize}">
	<input type="hidden" id="pageNo" name="pageNo" value="${pageNo}">
	<input type="hidden" id="pageSum" name="pageSum" value="${pageSum}">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 申请列表</strong></div>
    <table class="table table-hover text-center">
      <tr class="thead">
        <th style="text-align:left; padding-left:20px;width:5%">序号</th>
        <th style="width:10%">姓名</th>
        <th style="width:10%">手机号</th>
        <th style="width:5%">城市</th>
        <th style="width:10%">经销商等级</th>
        <th width="10%">注册时间</th>
        <th width="10%">申请状态</th>
        <th width="10%">操作</th>
        
      </tr>
      <c:forEach items="${List}" var="item" varStatus="vs">  
          	<tr class="fir">
			 <td style="text-align:left; padding-left:20px;">
                ${vs.count+pageInfo.startIndex+(pageNo-1)*15}
            </td>
            <td>${item.name}</td>
            <td>${item.phone}</td>
            <td>${item.city}</td>
            <td class="thisRoleName">${item.roleName}</td>
            <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td> <c:choose>
                   <c:when test="${item.sta==1}">待审核</c:when>
                   <c:when test="${item.sta==2}">驳回</c:when>
                   <c:when test="${item.sta==3}">通过</c:when>
               </c:choose></td>
			<td>
			    <c:if test="${item.sta==1}">
			     <div class="suspended-pos upgrade" gradeId="${item.gradeId}" roleKey="${item.roleKey}" openid="${item.openid}" onclick="upgrade(this)"><i class="fa fa-level-up"></i><span class="suspended">升级</span></div>
			      <div class="suspended-pos"><i class="fa fa-times" onclick="del('${item.gradeId}')"></i><span class="suspended">驳回</span></div>
			    </c:if>
			    <div class="suspended-pos"  onclick="javascript:look('${item.openid}')"><i class="fa fa-folder-open"></i><span class="suspended">详情</span></div>
			</td>
		</tr>            
	 </c:forEach>
     <c:if test="${empty List}">
		<tr>
        	<td colspan="5" class="t_c">
                <span class="no-records">暂无数据</span>
            </td>
        </tr>
      </c:if>
      <c:if test="${!empty List}">
	      <tr>
	        <td colspan="8">
	        	<div id="page" class="page_div"></div>
	        </td>
	      </tr>
	   </c:if>  
    </table>
  </div>
</form>
<script type="text/javascript" src="<%=path%>/admin/js/layer/layer.js" ></script>
<script type="text/javascript">
var li =""
for(var i = 0; i < cityData.length; i++) {
    var liText = cityData[i].label;
    var li = "<option value="+i+">"+ liText +"</option>";
    $("#cityData").append(li)
}
var paths = '<%=path%>'; 
var pageNo = Number($("#pageNo").val());
var totalSize = Number($("#totalSize").val());
var totalPage = Number($("#pageSum").val());
$('.ww').jeDate({
    isinitVal:false,
    /* format: 'YYYY-MM-DD hh:dd:mm' // 分隔符可以任意定义，该例子表示只显示年月 */
});

$(function(){
	page(pageNo,totalPage,totalSize);
})

//分页
function page(pageNo,totalPage,totalSize){
	$("#page").paging({
	    pageNo:pageNo,//当前页
	    totalPage: totalPage,//总页数
	    totalSize: totalSize,//总条数
	    callback: function(num) {
            newPage(num); 
       }
	})
	
}

function look(openid){
	window.location.href="<%=path%>/bUserInfo/registerlist?openid="+openid;
}
function newPage(pageNo){
    var params = new Object();
    params.pageNo = pageNo;
    $.ajax({ 
        type:"post",
        url:"<%=path %>/grade/newPage.html",
        data:params,
        dataType: "json",  
        timeout: 10000,  
        cache: false,  
        error: function(){
            alert("系统忙...");
        },
        success: function(data){
            var json=eval(data);
            pageNo = json.pageNo;
            pageSum = json.pageSum;
            count = json.count;
            var htmls = "";
         $.each(json.platfromList, function (index, item) {
        	  var xu=(pageNo-1)*15+index+1;
               htmls+='<tr class="fir">'
            	    +'<td style="text-align:left; padding-left:20px;">'+xu+'</td>'
                    +'<td>'+item.name+'</td>'
                    +'<td>'+item.phone+'</td>'
                    +'<td>'+item.city+'</td>'
                    +'<td class="thisRoleName">'+item.roleName+'</td>'
                    +'<td>'+getNowFormatDate(item.createTime)+'</td>';
               if(item.sta==1){
                   htmls+='<td>待审核</td>'
               }else if(item.sta==2){
                   htmls+='<td>驳回</td>'
               }else{
                   htmls+='<td>通过</td>' 
               }
               htmls+='<td>'
               if(item.sta==1){
            	htmls+='<div class="suspended-pos upgrade" gradeId="'+item.gradeId+'" roleKey="'+item.roleKey+'" openid="'+item.openid+'"  onclick="upgrade(this)"><i class="fa fa-level-up"></i><span class="suspended">升级</span></div>'
                htmls+='<div class="suspended-pos"><i class="fa fa-times" onclick="del('+item.gradeId+')"></i><span class="suspended">驳回</span></div>'
               }
               htmls+='<div class="suspended-pos downgrade"  onclick="javascript:look(\''+item.openid+'\')"><i class="fa fa-folder-open"></i><span class="suspended">详情</span></div>'
               htmls+='</td></tr>';
         });
         $(".fir").remove();
         $(".thead").after(htmls);
         if(htmls==""){
             $("#page").html("");
         }else{
             $("#page").html("");
            $("#page").paging({
                 pageNo:pageNo,//当前页
                 totalPage: pageSum,//总页数
                 totalSize: count,//总条数
                 callback: function(num) {
                     newPage(num); 
                }
             })
          }
        }   
    });
}
//搜索
function changesearch(){	
	 newPage(1);	
}
function upgrade(obj) {
	if(confirm("您确定要升级吗?")){
		var $this=$(obj)
	    var roleKey=Number($(obj).attr("roleKey"));
	    var openid=$(obj).attr("openid");
	    var gradeId = $(obj).attr("gradeId");
		$.ajax({
			url : paths + "/bUserInfo/updateState",
			type : "POST",
			dataType : "json",
			data : {
				"roleKey" : roleKey+1,
				"openid" : openid,
				"gradeId":gradeId
			},
			success : function(data) {
				 layer.msg(data.msg, {time: 2000},function(){
                     window.location.href="<%=path %>/grade/list";
                 });
			},
			error : function(r, s, m) {
			}
		});
	}
}

function del(id) {
    if(confirm("您确定驳回申请吗?")){
        $.ajax({
            url : paths + "/grade/updateState.html",
            data:{
            	id:id
            },
            type : "POST",
            dataType : "json",
            success : function(data) {
            	 layer.msg(data.msg, {time: 2000},function(){
            		 window.location.href="<%=path %>/grade/list";
                 });
            },
            error : function(r, s, m) {
            }
        });
    }
}
//批量停用启用
function DelSelect(obj){
    $("#listform").attr("action",paths+"/bUserInfo/delete");
    $("#state").val(obj);
    var Checkbox=false;
     $("input[name='id[]']").each(function(){
      if (this.checked==true) {     
        Checkbox=true;  
      }
    });
    if (Checkbox){
        var t=confirm("您确认要"+(obj==0?'停用':'启用')+"选中的用户吗？");
        if (t==false) return false;     
        $("#listform").submit();        
    }
    else{
        alert("请选择您要"+(obj==0?'停用':'启用')+"的用户!");
        return false;
    }
}

function updateRank(){
	 var arrayObj = new Array();  
	 var Checkbox=false;
     $("input[name='id[]']").each(function(){
      if (this.checked==true) {
    	arrayObj.push($(this).val()); 
        Checkbox=true;  
      }
     });
     if(Checkbox){
    	 layer.open({
             type: 2,
             title: '经销商等级',
             shadeClose: false,
             shade: 0.6,//遮罩透明度
             move:false,
             area: ['400px', '230px'],
             content: paths+'/bUserInfo/grade?args='+arrayObj,
             end: function(index){
            	 window.location.href="<%=path %>/bUserInfo/memberList";
             }
           });          
    }
    else{
        alert("请选择您要修改的用户!");
        return false;
    }
	
}

//全选
$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
      if (this.checked) {
          this.checked = false;
      }
      else {
          this.checked = true;
      }
  });
})

function getNowFormatDate(time) {
    var date = new Date(time);
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var h = 0;
    if (date.getHours() >= 0 && date.getHours() <= 9) {
        h = "0" + date.getHours();
    }else{
        h = date.getHours();
    }
    var m = 0;
    if (date.getMinutes() >= 0 && date.getMinutes() <= 9) {
        m = "0" + date.getMinutes();
    }else{
        m = date.getMinutes();
    }
    var s = 0;
    if (date.getSeconds() >= 0 && date.getSeconds() <= 9) {
        s = "0" + date.getSeconds();
    }else{
        s = date.getSeconds();
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate
            + " " + h + seperator2 + m
            + seperator2 + s;
    return currentdate;
}
</script>
</body>
</html>